import { connect } from '../../vendors/weapp-redux.js'
import { verifyPhoneNumber } from '../../redux/models/personal-info.js'

let pageConfig = {
  data: {
    phone: '',
    phoneInput: ''
  },
  verifyPhone(event) {
    this.verifyPhoneNumber(this.data.phoneInput)
    wx.navigateBack({
      delta: 1
    })
  },
  handlePhoneInput(event) {
    this.data.phoneInput = event.detail.value
  }
}

let mapStateToData = state => {
  return {
    phone: state.personal.phone
  }
}

let mapDispatchToPage = dispatch => ({
  verifyPhoneNumber: (phone, errorCallback) => dispatch(verifyPhoneNumber(phone, errorCallback))
})

pageConfig = connect(mapStateToData, mapDispatchToPage)(pageConfig)
Page(pageConfig)
